#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN=1e5;
struct node {
	double x,y;
	ll val;
};
node a[MAXN];
bool cmp(node a, node b) {
	return a.y/a.x < b.y/b.x;
}
int main() {
	int T;
	cin>>T;
	int n;
	ll cnt1;
	ll cnt2;
	ll res;
	while (T--) {
		scanf("%d", &n);
		cnt1=0;
		cnt2=0;
		for (int i=0; i<n; ++i) {
			scanf("%lf%lf%d", &a[i].x, &a[i].y, &a[i].val);
			if (a[i].x<0) cnt1+=a[i].val;
			else cnt2+=a[i].val;
		}
		sort(a, a+n, cmp);
		res=cnt1*cnt2;
		for (int i=0; i<n; ++i) {
			if (a[i].x<0) {
				cnt1-=a[i].val;
				cnt2+=a[i].val;
			}
			else {
				cnt1+=a[i].val;
				cnt2-=a[i].val;
			}
			if (cnt1*cnt2 > res) res=cnt1*cnt2;
		}
		cout<<res<<endl;
	}
	return 0;
} 
